<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function SuperType(name) {
            this.colors = ['red', 'black']
            this.name = name
        }
        SuperType.prototype.sayName = function () {
            console.log(this.name)
        }
        //借用构造函数 继承实例
        function SubType(name, age) {
            SuperType.call(this, name)
            this.age = age
        }

        function inheritPrototype(subType, superType) {
            var prototype = Object.create(superType.prototype); // 创建对象，创建父类原型的一个副本
            prototype.constructor = subType;                    // 增强对象，弥补因重写原型而失去的默认的constructor 属性
            subType.prototype = prototype;                      // 指定对象，将新创建的对象赋值给子类的原型
        }
        inheritPrototype(SubType, SuperType)
        SubType.prototype.sayAge = function () {
            console.log(this.age)
        }
        var instance1 = new SubType('zwj', 18)
        instance1.colors.push(1)
        instance1.sayAge()

        var instance2 = new SubType('zhangsan', 20)
        instance2.colors.push(2)
        console.log(instance2)



    </script>
</body>

</html>